import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import cn.edu.swu.design.R

//package com.oy.topline.fragment
//
//import android.content.Intent
//import android.content.IntentFilter
//import android.graphics.BitmapFactory
//import android.graphics.drawable.BitmapDrawable
//import android.graphics.drawable.Drawable
//import android.os.Bundle
//import android.view.*
//import android.widget.LinearLayout
//import android.widget.RelativeLayout
//import android.widget.Toast
//import androidx.fragment.app.Fragment
//import com.google.android.material.appbar.CollapsingToolbarLayout
//import com.oy.topline.R
//import com.oy.topline.activity.*
//import com.oy.topline.receiver.UpdateUserInfoReceiver
//import com.oy.topline.receiver.UpdateUserInfoReceiver.ACTION
//import com.oy.topline.receiver.UpdateUserInfoReceiver.INTENT_TYPE
//import com.oy.topline.utils.DBUtils
//import com.oy.topline.utils.UtilsHelper
//import de.hdodenhof.circleimageview.CircleImageView
//
class MeFragment : Fragment(), View.OnClickListener {
//    private var ll_calendar: LinearLayout? = null
//    private var ll_constellation: LinearLayout? = null
//    private var ll_scraw: LinearLayout? = null
//    private var ll_map: LinearLayout? = null
//    private var rl_collection: RelativeLayout? = null
//    private var rl_setting: RelativeLayout? = null
//    private var iv_avatar: CircleImageView? = null
//    private var view: View? = null
//    private var updateUserInfoReceiver: UpdateUserInfoReceiver? = null
//    private var filter: IntentFilter? = null
//    private var isLogin = false
//    private var collapsingToolbarLayout: CollapsingToolbarLayout? = null
    override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
    ): View? {
//        view = inflater.inflate(R.layout.fragment_me, container, false)
//        initView(view)
        return view
    }

//    private fun initView(view: View?) {
//        ll_calendar = view!!.findViewById<View>(R.id.ll_calendar) as LinearLayout
//        ll_constellation = view.findViewById<View>(R.id.ll_constellation) as LinearLayout
//        ll_scraw = view.findViewById<View>(R.id.ll_scraw) as LinearLayout
//        ll_map = view.findViewById<View>(R.id.ll_map) as LinearLayout
//        rl_collection = view.findViewById<View>(R.id.rl_collection) as RelativeLayout
//        rl_setting = view.findViewById<View>(R.id.rl_setting) as RelativeLayout
//        iv_avatar = view.findViewById<View>(R.id.iv_avatar) as CircleImageView
//        collapsingToolbarLayout =
//            view.findViewById<View>(R.id.collapsing_tool_bar) as CollapsingToolbarLayout
//        collapsingToolbarLayout!!.setExpandedTitleTextAppearance(R.style.ToolbarTitle)
//        isLogin = UtilsHelper.readLoginStatus(activity)
//        setLoginParams(isLogin)
//        setListener()
//        receiver()
//    }
//
//    private fun receiver() {
//        updateUserInfoReceiver = UpdateUserInfoReceiver { context, intent ->
//            val action = intent.action
//            if (ACTION.Companion.UPDATE_USERINFO
//                == action
//            ) {
//                val type = intent.getStringExtra(INTENT_TYPE.Companion.TYPE_NAME)
//                if (INTENT_TYPE.Companion.UPDATE_HEAD //更新头像
//                    == type
//                ) {
//                    val head = intent.getStringExtra("head")
//                    val bt = BitmapFactory.decodeFile(head)
//                    if (bt != null) {
//                        val drawable: Drawable = BitmapDrawable(bt)
//                        iv_avatar!!.setImageDrawable(drawable)
//                    } else {
//                        iv_avatar!!.setImageResource(R.drawable.default_head)
//                    }
//                }
//            }
//        }
//        filter = IntentFilter(ACTION.Companion.UPDATE_USERINFO)
//        activity!!.registerReceiver(updateUserInfoReceiver, filter)
//    }
//
//    private fun setListener() {
//        ll_calendar!!.setOnClickListener(this)
//        ll_constellation!!.setOnClickListener(this)
//        ll_scraw!!.setOnClickListener(this)
//        ll_map!!.setOnClickListener(this)
//        rl_collection!!.setOnClickListener(this)
//        rl_setting!!.setOnClickListener(this)
//        iv_avatar!!.setOnClickListener(this)
//    }
//
//    override fun onDestroy() {
//        super.onDestroy()
//        if (updateUserInfoReceiver != null) {
//            activity!!.unregisterReceiver(updateUserInfoReceiver)
//        }
//    }
//
    override fun onClick(view: View) {
//        when (view.id) {
//            R.id.ll_calendar -> {
//                val calendarIntent = Intent(activity, CalendarActivity::class.java)
//                startActivity(calendarIntent)
//            }
//            R.id.ll_constellation -> {
//                val constellIntent = Intent(activity, ConstellationActivity::class.java)
//                startActivity(constellIntent)
//            }
//            R.id.ll_scraw -> {
//                val scarwIntent = Intent(activity, ScrawActivity::class.java)
//                startActivity(scarwIntent)
//            }
//            R.id.ll_map -> {
//                val mapIntent = Intent(activity, MapActivity::class.java)
//                startActivity(mapIntent)
//            }
//            R.id.rl_collection -> if (isLogin) {
//                val collection = Intent(activity, CollectionActivity::class.java)
//                startActivity(collection)
//            } else {
//                Toast.makeText(
//                    activity, "您还未登录，请先登录",
//                    Toast.LENGTH_SHORT
//                ).show()
//            }
//            R.id.rl_setting -> if (isLogin) {
//                //跳转到设置界面
//                val settingIntent = Intent(activity, SettingActivity::class.java)
//                startActivityForResult(settingIntent, 1)
//            } else {
//                Toast.makeText(
//                    activity, "您还未登录，请先登录",
//                    Toast.LENGTH_SHORT
//                ).show()
//            }
//            R.id.iv_avatar -> if (isLogin) {
//                //跳转到个人资料界面
//                val userinfo = Intent(activity, UserInfoActivity::class.java)
//                startActivity(userinfo)
//            } else {
//                //跳转到登录界面
//                val login = Intent(activity, LoginActivity::class.java)
//                startActivityForResult(login, 1)
//            }
//        }
    }
//
//    /**
//     * 登录成功后设置我的界面
//     */
//    fun setLoginParams(isLogin: Boolean) {
//        if (isLogin) {
//            val userName = UtilsHelper.readLoginUserName(activity)
//            collapsingToolbarLayout!!.title = userName
//            val head: String = DBUtils.Companion.getInstance(activity)!!.getUserHead(userName)
//            val bt = BitmapFactory.decodeFile(head)
//            if (bt != null) {
//                val drawable: Drawable = BitmapDrawable(bt) //转换成drawable
//                iv_avatar!!.setImageDrawable(drawable)
//            } else {
//                iv_avatar!!.setImageResource(R.drawable.default_head)
//            }
//        } else {
//            iv_avatar!!.setImageResource(R.drawable.default_head)
//            collapsingToolbarLayout!!.title = "点击登录"
//        }
//    }
//
//    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
//        super.onActivityResult(requestCode, resultCode, data)
//        if (data != null) {
//            val isLogin = data.getBooleanExtra("isLogin", false)
//            setLoginParams(isLogin)
//            this.isLogin = isLogin
//        }
//    }
}